package com.aw.baselib.adapter

import com.aw.baselib.R
import com.aw.baselib.bean.CommonListBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

/**
 * Created by hzw.
 */
class CommonListAdapter :
    BaseQuickAdapter<CommonListBean?, BaseViewHolder>(R.layout.view_item_common_pupupwidow) {
    private var mList: MutableList<out CommonListBean>? = ArrayList()

    init {
        if (mList == null) {
            mList = ArrayList()
        }
    }

    override fun convert(helper: BaseViewHolder, bean: CommonListBean?) {
        if (bean == null) {
            return
        }
        helper.setText(R.id.tv_name, bean.itemName)
    }

    fun addAllData(dataList: MutableList<out CommonListBean>?) {
        mList = dataList
        setNewData(mList as List<CommonListBean>?)
        notifyDataSetChanged()
    }

    fun clearData() {
        if (mList != null) {
            val startPosition = 0 //hasHeader is 1
            val preSize = mList!!.size
            if (preSize > 0) {
                mList!!.clear()
                notifyItemRangeRemoved(startPosition, preSize)
            }
        }
    }
}